package com.atguigu.school.controller;

import com.atguigu.school.commons.Page;
import com.atguigu.school.commons.Result;
import com.atguigu.school.mapper.ClazzMapper;
import com.atguigu.school.pojo.Clazz;
import com.atguigu.school.service.ClazzService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "班级控制器")
@RestController
@RequestMapping("/sms/clazzController")
public class ClazzController {

    /**
     * 处理班级相关业务
     */
    @Autowired
    private ClazzService clazzService;

    @PostMapping("/saveOrUpdateClazz")
    @ApiOperation(value = "新增或更新班级", notes = "如果没有携带 id 就是新增，否则就是更新")
    public Result saveOrUpdateClazz(@RequestBody Clazz clazz) {
        this.clazzService.saveOrUpdateClazz(clazz);
        return Result.ok();
    }

    @DeleteMapping("/deleteClazz")
    @ApiOperation(value = "批量删除班级")
    @ApiImplicitParam(name = "ids", value = "预删除班级的 id 列表")
    public Result deleteClazz(@RequestBody List<Integer> ids) {
        this.clazzService.deleteClazzByIds(ids);
        return Result.ok();
    }

    @GetMapping("/getClazzsByOpr/{pageNo}/{pageSize}")
    @ApiOperation(value = "分页查询班级", notes = "目前只支持根据名称和所属年级名称查")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNo", value = "当前页，从 1 开始"),
            @ApiImplicitParam(name = "pageSize", value = "每页长度")
    })
    public Result getClazzByOpr(@PathVariable("pageNo") Integer pageNo, @PathVariable("pageSize") Integer pageSize, Clazz clazz) {
        Page<Clazz> page = this.clazzService.selectClazzByNameAndGradeName(clazz.getName(), clazz.getGradeName(), pageNo, pageSize);
        return Result.ok(page);
    }

    @GetMapping("/getClazzs")
    @ApiOperation(value = "获取所有教师")
    public Result getClazzs() {
        return Result.ok(this.clazzService.selectClazz());
    }

}
